; Boot sector for CoBra 860K CP/M, modified to allow use of all drives (0-3) as DSDD 860K drives

; Written 2017-02-03

	ORG	$0000

	JR	START

	DEFB	$00
	DEFB	$80
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00
	DEFB	$00

START:	DI
	LD	HL,$0100
	LD	SP,HL		; set stack at $0100
	LD	A,$92		; control word for 8255: Mode Set flag=active,
				; 			Group A: Select Mode 0,
				;				 Port A set to Input mode,
				;				 Port C (upper half) set to Output Mode,
				;			Group B: Select Mode 0,
				;				 Port B set to Input Mode,
				;				 Port C (lower half) set to Output Mode
	OUT	($DF),A		; write control word to 8255
	OUT	($DF),A		; write control word to 8255 (again !?)
	LD	A,$41
	OUT	($FE),A		; set 06 to "1" for VRAM access, border to blue
	LD	DE,$6200
	LD	BC,$1E00
	LDIR			; copy $0100-$1EFF to $6200-$7FFF		(BLOCK#1+CCP)	BLOCK#1=$0100-$16FF (5632 bytes), CCP=$1700-$1EFF (2048 bytes)
	LD	DE,$E800
	LD	BC,$1800
	LDIR			; copy $1F00-$36FF to $E800-$FFFF		(BDOS+BIOS)	BDOS=$1F00-$2CFF (3584 bytes), BIOS=$2D00-$36FF (2560 bytes)

			; ################### BIOS MODIFICATIONS ######################
	LD	A,$D9		; ----------- BIOS DPH area ------------
	LD	($FB00),A	; change XLT in DPH#0 in BIOS
	LD	($FB10),A	; change XLT in DPH#1 in BIOS
;	LD	($FB40),A	; change XLT in DPH#4 in BIOS
	LD	A,$CA
	LD	($FB0A),A	; change DPB in DPH#0 in BIOS
	LD	($FB1A),A	; change DPB in DPH#1 in BIOS
;	LD	($FB4A),A	; change DPB in DPH#4 in BIOS
;	LD	($F659),A	; change DPB addr stored parameter in BIOS
	LD	HL,$FDA0
	LD	($FB1C),HL	; change CSV in DPH#1 to $FDA0 (for DD it is double the size of SD, so we have to move CSV area somewhere else)
	LD	HL,$FE60
	LD	($FB1E),HL	; change ALV in DPH#1 to $FDC0 (for DD it is double the size of SD, so we have to move CSV area somewhere else)
				; ----------- BIOS SECTRAN fix for A:,B: to be 860K DSDD drives -----------
	LD	HL,$0000
	LD	($F80C),HL	; changes 2804="JR Z,$F812" to NOP NOP
				; ----------- BIOS BLOCK#1 fix for A:,B: to be the same as C:,D: ----------
	LD	($7035),HL	; changes 2808="JR Z,$703F" to NOP NOP
	LD	($6EA9),HL	; changes 2802="JR Z,$6EAD" to NOP NOP
	LD	($70AC),HL	; changes 2805="JR Z,$70B3" to NOP NOP
	LD	A,$18
	LD	($6EC3),A	; changes $20="JR NZ, ..." to "JR ..."
			; #############################################################

;	RES	6,A		; A=$01
	LD	A,$01		; A=$01
	OUT	($FE),A		; set 06 to "0" for DRAM access
	LD	HL,$3700
	LD	DE,$0100
	LD	BC,$0900
	LDIR			; copy $3700-$3FFF to $0100-$09FF		(DEMO?)		DEMO=$3700-$3FFF (2304 bytes)
	LD	BC,$0000
	JP	$F600		; jump to start of BIOS (BIOS function #0, BOOT)